package com.fly.caihong.utils;

import com.fly.caihong.view.PullRefreshRecyclerView;

import java.util.List;

/**
 * 创建时间：2018/8/17 0017 11:16
 * 创建人：fly
 * 功能描述：列表分页包装器
 */
public class PageWrapper {

    private int mPageNum = 1;
    private int mPageTotal = 1;
    private PullRefreshRecyclerView mSmartLayout;

    public PageWrapper(PullRefreshRecyclerView smartLayout) {
        this.mSmartLayout = smartLayout;
    }


    /**
     * 数据加载成功
     *
     * @param newData 新数据集合
     */
    public void notifyDataSuccess(List newData) {
        mSmartLayout.addData(newData);
        if (newData.size() == 0 && mPageNum == 1) {
            mSmartLayout.setPullEmptyView();
        } else if (newData.size() < 10) {
            mSmartLayout.loadMoreEnd();
        } else {
            mSmartLayout.loadMoreComplete();
        }
        mPageNum++;
    }

    /**
     * 数据加载失败
     */
    public void notifyDataFailure() {
        mSmartLayout.loadMoreFail();
    }

    /**
     * 是否最后一页
     *
     * @return
     */
    public boolean isLastPage() {
        return mPageTotal > 0 && mPageNum > mPageTotal;
    }

    /**
     * 是后第一页
     *
     * @return
     */
    public boolean isFirstPage() {
        return mPageNum <= 1;
    }

    /**
     * 重置页码为第一页
     */
    public void resetPageNum() {
        mPageNum = 1;
    }

    /**
     * 获取当前分页页码
     *
     * @return
     */
    public int getPageNum() {
        return mPageNum;
    }

}
